package servlet;



import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.PreparedStatement;

public class InventoryaddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int iid =Integer.parseInt(request.getParameter("iid"));
        String type =request.getParameter("type");
        int wid=Integer.parseInt(request.getParameter("wid"));
        String wname =request.getParameter("wname");
        int number=Integer.parseInt(request.getParameter("number"));
        String staff =request.getParameter("staff");

        String sql ="INSERT INTO inventory VALUES (?,?,?,?,?,?)";

        PreparedStatement ps;
        try {
            ps = JdbcUtil.getConnection().prepareStatement(sql);
            ps.setInt(1,iid);
            ps.setString(2, type);
            ps.setInt(3, wid);
            ps.setString(4, wname);
            ps.setInt(5, number);
            ps.setString(6, staff);
            int up = ps.executeUpdate();
            if(up==1){
                request.getRequestDispatcher("inventory.jsp").forward(request, response);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }




    }
}
